<template>
  <div>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" icon="" size="mini" @click="exportExcel">一键赠送</el-button>
      </el-col>
    </el-row>
    <el-table height="400px" :data="list" @selection-change="handleSelectionChange" stripe border>
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" prop="index" align="center" width="60" />
      <el-table-column label="用户UID" prop="userId" align="center" />
      <el-table-column label="赠送等级" prop="vipLevel" align="center" />
      <el-table-column label="赠送天数" prop="dayNum" align="center" />
      <el-table-column label="赠送说明" prop="remark" width="250" />
    </el-table>
  </div>
</template>

<script>
export default {
  props: {
    list: {
      type: Array
    }
  },
  data() {
    return {
      selectArray: []
    }
  },

  methods: {
    handleSelectionChange(val) {
      this.selectArray = val;

    },

    exportExcel() {
      var isPass = 1;

      this.selectArray.forEach((item, index, array) => {

        if (!item.userId || !item.vipLevel || !item.dayNum || !item.remark) {
          let i = '序号---"' + item.index + ',"数据不能为空'
          this.$modal.msgError(i);
          isPass = 0;
          return;
        }

        let userId = String(item.userId);
        let vipLevel = String(item.vipLevel);
        let dayNum = String(item.dayNum);

        userId = userId.replace(/\s*/g, "")
        vipLevel = vipLevel.replace(/\s*/g, "")
        dayNum = dayNum.replace(/\s*/g, "")

        item.userId = userId;
        item.vipLevel = vipLevel;
        item.dayNum = dayNum.replace(/\s*/g, "")

      })

      if (isPass) {
        this.$emit('submit', this.selectArray)
      }
    }
  }

}
</script>

<style>
</style>
